<style>
.ui-datepicker-current{color:red !important;font-weight: bold !important;}
#UserRoleRoleId{color:orange;}
#UserRoleStartedYmd,#UserRoleStartedHis{ font-weight: bold;   text-align: center;}
#UserRoleEndedYmd,#UserRoleEndedHis{  font-weight: bold;  text-align: center;color:orange;}
</style>
<div class="users form">
{{if $current_action=='admin_add'}}
<?php 
echo $this->MForm->create($current_model,array(    
	'url' => array('action' => 'add'),
));
?>
{{elseif $current_action=='admin_edit'}}
 <?php 
echo $this->MForm->create($current_model,array(
    'url' => array('action' => 'edit',$id,$copy),
));
?>
{{/if}}
    <fieldset>
    
    {{$this->MForm->input('id')}}
    <?php
    
        echo $this->MForm->input('role_id');
		if($current_action=='admin_add'){
			$after = '<p>一个用户在一个用户组下只能加入一次。<br/>选择角色，输入用户编号后，点击空白区域，检测用户是否已有权限，并加载其开始结束时间进行修改
<br/><a class="btn btn-sm btn-warning" href="javascript:loadRoleInfo();">手动检测</a></p>
';
		}
        echo $this->MForm->input('user_id',array('type'=>'text','after'=>$after));

	echo $this->MForm->input('status');
//echo $this->MForm->input('started',array('type'=>'date'));
//echo $this->MForm->input('ended',array('type'=>'date'));

echo $this->MForm->autoFormElement('UserRole','started',$ext_schemas['started'],array('his'=>'23:59:59'));
echo $this->MForm->autoFormElement('UserRole','ended',$ext_schemas['ended'],array('his'=>'23:59:59'));
?>
    </fieldset>
    <div class="form-group">
		<label class="col-sm-2 control-label" for="ProductName"></label>
		<div class="col-sm-9"><input class="btn btn-primary" type="submit" value="{{__('Submit')}}"></div>
	</div>
<?php echo $this->MForm->end();?>
</div>

{{if $current_action=='admin_edit'}}
<div class="alert alert-warning">
    <p>提示：修改为当前时间之前的时间即为权限过期</p>
</div>
{{/if}}

<script>
function loadRoleInfo(){
	$('#UserRoleId').val('');
	var url = ADMIN_BASEURL+'/admin/user_roles/query/'+ $('#UserRoleRoleId').val() + '/' + $('#UserRoleUserId').val();
	ajaxAction(url,{},null,function(response){
		if(response.ret == 1) {
			$('#UserRoleId').val(response.data.id);
			
			$('#UserRoleStartedYmd').val(response.data.StartedYmd);
			$('#UserRoleStartedHis').val(response.data.StartedHis);
			
			$('#UserRoleEndedYmd').val(response.data.EndedYmd);
			$('#UserRoleEndedHis').val(response.data.EndedHis);
			showSuccessMessage('已成功加载数据');
		}
		else{
			showSuccessMessage('没有检测到数据，添加新的吧');
			$('#UserRoleId').val('');
		}
	});
}

$(function(){
	$('#UserRoleRoleId').on('change',function(){
		loadRoleInfo();
	})
	$('#UserRoleUserId').on('blur',function(){
		loadRoleInfo();
	})
})
</script>